<?php namespace app\common\model;

use think\Loader;
use think\Validate;
use houdunwang\arr\Arr;
use think\db;
//图片模型
class Banner extends Base{

	
	
	//添加文章
	public function addData($data){
		
		$validate = Loader::validate('Banner');
		if(!$validate->check($data)){
		    return ['valid'=>0,'msg'=>$validate->getError()];
		}else{
		    
			$num=db('banner')->insert($data);
			if($num){
				 return ['valid'=>1,'msg'=>'数据添加成功！'];
			}else{
				 return ['valid'=>0,'msg'=>'数据添加失败！'];
			}
			
		}
		
	}
	//编辑栏目
	public function editData($data){
	   $validate = Loader::validate('Banner');
		if(!$validate->check($data)){
		    return ['valid'=>0,'msg'=>$validate->getError()];
		}else{
			
			$id=db('banner')
			    ->where('pcid',$data['pcid'])
			    ->update($data);
            if($id){
            	return ['valid'=>1,'msg'=>'数据修改成功！'];
            }else{
            	return ['valid'=>0,'msg'=>'数据修改失败！'];
            }
			 
		}
		
		
	}
	
	//获得所有的子类
	public function getSon($data,$cid){
		$arr=array();
	   if(!is_array($data)){
	   	
	     	return false;
		 }
	   foreach($data as $k=>$v){
	   	  if($v['pid']==$cid){
	   	  	//把子类的cid压入数组
	   	  	 $arr[]=$v['cid'];
			 //把父类的cid也压入数组
			
			 $arr=array_merge($arr,$this->getSon($data,$v['cid']));
//			 $arr=$this->getSon($data,$v['cid']);
	   	  }
		
	   }
	    $arr[]=$cid;//注意很容易丢失
	   return $arr;
	}




	
}
